package operation;

import book.BookList;
import book.Book;

import java.util.Scanner;

public class BorrowOperation implements IOPeration{

    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书！");

         /*
             1. 你要借阅哪本书？
             2.你借阅的图书在不在？
             3.在的话置为true
          */

        System.out.println("输入你要借阅的图书:");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int useSize = bookList.getUsedSize();
        int i = 0;
        for(i = 0;i < useSize;i++){
            Book book = bookList.getBook(i);
            if(name.equals(bookList.getBook(i).getName()) && book.isBorrowed() == false){
                book.setBorrowed(true);
                System.out.println("借阅成功!");
                System.out.println(book);
                return;
            }
        }

        if(i == useSize) {
            System.out.println("你借阅的图书不存在!");
        }
    }
}
